package com.example.baselib.dialog


import android.content.DialogInterface
import android.content.Intent
import android.util.Log
import android.view.*
import com.example.baselib.R
import kotlinx.android.synthetic.main.dialog_msg.*
import kotlinx.android.synthetic.main.dialog_msg.view.*

/**
 * Author: sxygsj
 * Date: 2020/4/13 14:30
 * Description: 消息提示Dialog
 * History:
 * <author> <time> <version> <desc>
 * 作者姓名 修改时间 版本号 描述
 */
class MsgDialog(var msg: String ) : BaseDialogFragment() {
    var callback: onDismissCallback? = null
    override fun getContentLayout(): Int {
        return R.layout.dialog_msg
    }

    override fun initView(view: View) {
        view.msg_dialog_btn.setOnClickListener {
            if (msg.split("！")[0] == "登录信息已过期，请重新登录"){
                Log.i("MSGGGGG",msg.split("！")[0])
                val i = activity?.applicationContext?.packageManager
                    ?.getLaunchIntentForPackage(activity!!.applicationContext.packageName)
                i?.flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
                startActivity(i)
                activity?.finish()
            }
            dismiss()
        }
        view.msg_dialog_txt.text=msg
    }

    override fun initData() {

    }

    override fun onDismiss(dialog: DialogInterface) {
        super.onDismiss(dialog)
        callback?.dismiss()
    }

    fun setCallbackListener(callback: onDismissCallback) :MsgDialog{
        this.callback=callback
        return this
    }

    interface onDismissCallback {
        fun dismiss()
    }

}